﻿using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;

namespace Digitalmes.WebApi.Infrastructure.Jwt;

/// <summary>
/// 表示实现对象 JWT 验证管理器。
/// </summary>
public interface IJwtAuthManager
{
    /// <summary>
    /// 生成 Jwt Token。
    /// </summary>
    /// <param name="claims">声明集合</param>
    /// <param name="now"></param>
    /// <param name="expires">过期时长</param>
    /// <returns></returns>
    string GenerateToken(Claim[] claims, DateTime now, TimeSpan expires);

    /// <summary>
    /// 刷新 Jwt Token。
    /// </summary>
    /// <param name="refreshToken"></param>
    /// <param name="now"></param>
    /// <param name="expires">过期时长</param>
    /// <returns></returns>
    /// <exception cref="SecurityTokenException" />
    string Refresh(string refreshToken, DateTime now, TimeSpan expires);

    /// <summary>
    /// 解构 Token。
    /// </summary>
    /// <param name="token"></param>
    /// <returns></returns>
    /// <exception cref="SecurityTokenException" />
    (ClaimsPrincipal, JwtSecurityToken?) DecodeJwtToken(string token);
}
